package com.zipou.framework.gwt.client.widget.fromWrapper;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.user.client.rpc.IsSerializable;
import com.google.gwt.user.client.ui.Widget;
import com.zipou.framework.gwt.client.widget.MyTextBox;

public class FormWidgetWrapper<T extends Widget> {

	private T w;
		
	private List<OnErrorTest> onErrorTest = null;

	public FormWidgetWrapper(T widget) {
		this.w = widget;
		this.onErrorTest = new ArrayList<OnErrorTest>();
	}

	public T getWidget() {
		return w;
	}

	public void addOnErrorTest(OnErrorTest handler) {
		this.onErrorTest.add(handler);
	}
	
	public boolean isValid() throws FormException {
		if (this.onErrorTest.size() != 0) {
			for (OnErrorTest handler : this.onErrorTest) {
				if (handler.isWrong()) {
					throw new FormException(handler.message());
				}
			}
		}
		return true;
	}
}
